#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>

using namespace std;

string ReverseWords1(string s)
{	
	int start = 0;
	int end = s.find(' ', start) - 1;
	if (s.find(' ', start) == string::npos)
	{
		end = s.size() - 1;
	}
	while(start != string::npos)
	{
		while (start < end)
		{
			char temp = s[start];
			s[start] = s[end];
			s[end] = temp;
			++start;
			--end;
		}
		start = s.find(' ', start) + 1;
		if (start == 0)
		{
			break;
		}
		if (s.find(' ', start) == string::npos)
		{
			end = s.size() - 1;
		}
		else
		{
			end = s.find(' ', start) - 1;
		}
	}
	return s;
}

string ReverseWords2(string s)
{	
	string ret;
	int i = 0;
	int length = s.size();
	while (i < length)
	{
		int start = i;
		while (i < length && s[i] != ' ')
		{
			++i;
		}
		for (int j = 0; j < i - start; j++)
		{
			ret.push_back(s[i - 1 - j]);
		}
		while (i < length && s[i] == ' ')
		{
			++i;
			ret.push_back(' ');
		}
	}
	return ret;
}

int main()
{
	string s;
	getline(cin, s);
	cout << s << endl;
	//cout << ReverseWords1(s) << endl;
	cout << ReverseWords2(s) << endl;
	return 0;
}